//ip="123.207.251.172"
ip="localhost"
function initUserInfo() {

    get("http://"+ip+"/data/request/index", function (data) {
        if (data.code === 200) {

            $("#profile-name").text(data.reason);
            $("#avatar_path").attr("src",data.t);
        } else if (data.code == 500) {
            alert(data.reason)
            window.location = "login.html"
        }

    }, function () {

    })
}
function get(url, success, error) {
    $.ajax({
        type: "get",
        url: url,
        async: true,
        dataType: 'json',
        beforeSend: function (xhr) {
            xhr.setRequestHeader("token", localStorage.getItem('token'))
        },
        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}
function get_with_data(url, data,success, error) {
    $.ajax({
        type: "get",
        url: url,
        async: true,
        data: data,
        dataType: 'json',
        beforeSend: function (xhr) {
            xhr.setRequestHeader("token", localStorage.getItem('token'))
        },
        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}
function post(url, data, success, error) {
    $.ajax({
        type: "post",
        url: url,
        async: true,
        data: data,
        dataType: 'json',
        beforeSend: function (xhr) {
            xhr.setRequestHeader("token", localStorage.getItem('token'))
        },
        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}

function post_without_token(url, data, success, error) {
    $.ajax({
        type: "post",
        url: url,
        async: true,
        data: data,
        dataType: 'json',

        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}